#pragma once
#include "Device\Port.h"
#include "NetSdk\netsdk.h"
#include "NetSdk\H264Play.h"
#include "PictureEx.h"

#include "File\FileButler.h"

#define FONT_SIZE_PORT_NAME		200
#define FONT_SIZE_TALK_STATUS	140

typedef struct {
	CRect       mSpeakerImgPos;
	CRect       mWarningImgPos;
	CRect       mPhoneImgPos;

	CRect       mPortNamePos;
	CRect       mTalkStatusPos;
	CRect       mTalkReqTextPos;


}StatusBarLayoutInfo;


class CFuckButton : public CButton
{
	DECLARE_DYNAMIC(CFuckButton)

public:
	CFuckButton();
	virtual ~CFuckButton();

	//CFont* Font;
protected:
	DECLARE_MESSAGE_MAP()

public:
	virtual BOOL PreTranslateMessage(MSG* pMsg);
};



class CHolder  :
	public CWnd
{
public:
	CHolder();
	virtual ~CHolder();


public:
	CFileButler                 mFileButler;



	void                        BindPort(CPort* pPort);
	void                        CreateHolder(CWnd* pParent);

	//bool                        IsAlarmRecording();
	bool                        IsRealplaying();
	//bool                        IsRecording();

	//CFile*                      GetAlarmRecordFile();

	bool						mGifLoading;
	bool						mLoging;


	CCamera*                    GetBindedCamera();
	CPort*                      GetBindedPort();


	CRect						mTitleRect;

	long                        GetPlayPort();
	long                        GetRealplayHandle();
	//CFile*                      GetRecordFile();
	HWND                        GetSurfaceHandle() ;

	void                        HandleAlarmEvent(int status);
	void                        OnCameraLogin();
	void                        OnCameraLogout();
	void                        OnAlarmBegin();
	void                        OnAlarmEnd();

	void						SetPos() ;
	void                        SetPos(CRect& r);

	void                        UpdateStatusBarLayout();
	
	void						SetTalkStatus(TalkStatus status);

	CPictureEx&					GetGifControl();

	CButton&					GetReverseBtn();
	CButton&					GetDeleteBtn();

protected:
	TalkStatus                  mTalkStatus;
	StatusBarLayoutInfo         mStatusLayout;
	int                         mAlarmStamp;
	//CFileButler                 mRecordFileButler;
	//CFileButler                 mAlarmRecordFileButler;



	H264_DVR_CLIENTINFO         mClientInfo;

	bool                        mHasFocus;
	bool                        mIsLargeMode;

	bool                        mIsRealPlaying;
	bool                        mHasConnectedRealPlay;

	bool                        mIsAlarming;
	//bool                        mIsAlmRecording;
	bool                        mIsAutoAlarmRecording;

	bool                        mIsAutoRecording;
	//bool                        mIsRecording;


	bool                        mIsWatching;
	bool                        mIsAutoWatching;

	long                        mPlayPort;
	CPort*                      mPort;
	CCamera*                    mCamera;
	long                        mRealPlayHandle;
	CRect                       mSplitPos;	

	//CStatic                     mSpeakerIcon;
	//CStatic                     mTalkStatusIcon;
	CStatic                     mPortNameLabel;
	CStatic                     mTalkStatusLabel;
	CPictureEx                  mGifSurface;
	CString                     mTalkStatusText;

	bool                        mIsSpeakerIconVisible;
	bool                        mIsTalkStatusIconVisible;
	bool                        mIsTalkMiss;
	bool                        mIsTalking;
	bool                        mIsReqTalking;



	CRect                       mSpeakerPos;
	CRect                       mTalkStatusPos;
	CRect                       mPortNamePos;
	CRect                       mTalkStatusTextPos;

	bool                        ConnectRealPlay();
	void                        DisconnectRealPlay();

	void                        ExecuteConfig();
	UINT                        GetNextWatchElapse(CTime& refTime, UINT begin, UINT end);
	void                        SetIndicator(CStatic&, HBITMAP);

	bool                        IsWatchTime(CTime& refTime, UINT begin, UINT end);

	//bool                        StartAlarmRecord();
    //void                        StartAutoAlarmRecord();
	//void                        StartAutoRecord();
	void                        StartAutoWatch();
	bool                        StartRealPlay();
	//bool                        StartRecord();
	void                        StartWatch();

	//void                        StopAutoAlarmRecord();
	//void                        StopAlarmRecord();
	//void                        StopAutoRecord();
	void                        StopRealPlay();
	//void                        StopRecord();
	void                        StopWatch();
	void                        StopAutoWatch();

	void                        InitView();
	void                        UpdateLayout();	


private:
	CFuckButton                  mReverseBtn;
	CFuckButton                  mDeleteBtn;

	CWnd						 mSurface;


public:
	virtual BOOL PreTranslateMessage(MSG* pMsg);
	DECLARE_MESSAGE_MAP()
	afx_msg void OnKillFocus(CWnd* pNewWnd);
	afx_msg void OnTimer(UINT_PTR nIDEvent);
	afx_msg void OnSetFocus(CWnd* pOldWnd);
	afx_msg void OnNcPaint();
	afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
	afx_msg void OnSize(UINT nType, int cx, int cy);
	afx_msg void OnPaint();
	afx_msg void OnDrawItem(int nIDCtl, LPDRAWITEMSTRUCT lpDrawItemStruct);
	afx_msg HBRUSH OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor);
	afx_msg BOOL OnEraseBkgnd(CDC* pDC);
protected:
	afx_msg LRESULT OnUserMsgTimeLinePluse(WPARAM wParam, LPARAM lParam);
	afx_msg LRESULT OnUserMsgAlarmStart(WPARAM wParam, LPARAM lParam);
	afx_msg LRESULT OnUserMsgPortConfig(WPARAM wParam, LPARAM lParam);
	afx_msg LRESULT OnUserMsgSystemConfig(WPARAM wParam, LPARAM lParam);
	afx_msg LRESULT OnUserMsgNotifyKey(WPARAM wParam, LPARAM lParam);
	afx_msg LRESULT OnUserMsgLoadGifOk(WPARAM wParam, LPARAM lParam);
};

